import request from './request'

// 创建通知
export const createNotification = (data) => {
  return request({
    url: '/api/notifications',
    method: 'post',
    data
  })
}

// 创建系统通知
export const createSystemNotification = (data) => {
  return request({
    url: '/api/notifications/system',
    method: 'post',
    data
  })
}

// 创建预约通知
export const createAppointmentNotification = (data) => {
  return request({
    url: '/api/notifications/appointment',
    method: 'post',
    data
  })
}

// 创建健康提醒
export const createHealthReminder = (data) => {
  return request({
    url: '/api/notifications/health-reminder',
    method: 'post',
    data
  })
}

// 创建分析通知
export const createAnalysisNotification = (data) => {
  return request({
    url: '/api/notifications/analysis',
    method: 'post',
    data
  })
}

// 创建症状评估通知
export const createSymptomAssessmentNotification = (data) => {
  return request({
    url: '/api/notifications/symptom-assessment',
    method: 'post',
    data
  })
}

// 创建定时提醒
export const createScheduledReminder = (data) => {
  return request({
    url: '/api/notifications/scheduled-reminder',
    method: 'post',
    data
  })
}

// 创建紧急通知
export const createEmergencyNotification = (data) => {
  return request({
    url: '/api/notifications/emergency',
    method: 'post',
    data
  })
}

// 创建广播通知
export const createBroadcastNotification = (data) => {
  return request({
    url: '/api/notifications/broadcast',
    method: 'post',
    data
  })
}

// 批量创建通知
export const batchCreateNotifications = (data) => {
  return request({
    url: '/api/notifications/batch',
    method: 'post',
    data
  })
}

// 获取用户通知列表
export const getUserNotifications = (params) => {
  return request({
    url: `/api/notifications/user/${params.userId}`,
    method: 'get',
    params: {
      page: params.page,
      size: params.size,
      type: params.type,
      priority: params.priority,
      isRead: params.isRead
    }
  })
}

// 获取最近通知
export const getRecentNotifications = (userId, limit = 10) => {
  return request({
    url: `/api/notifications/user/${userId}/recent`,
    method: 'get',
    params: { limit }
  })
}

// 获取未读通知数量
export const getUnreadNotificationCount = (userId) => {
  return request({
    url: `/api/notifications/user/${userId}/unread-count`,
    method: 'get'
  })
}

// 获取按类型分组的未读通知数量
export const getUnreadNotificationCountByType = (userId) => {
  return request({
    url: `/api/notifications/user/${userId}/unread-count-by-type`,
    method: 'get'
  })
}

// 获取高优先级未读通知
export const getHighPriorityUnreadNotifications = (userId) => {
  return request({
    url: `/api/notifications/user/${userId}/high-priority-unread`,
    method: 'get'
  })
}

// 标记通知为已读
export const markAsRead = (userId, notificationId) => {
  return request({
    url: `/api/notifications/user/${userId}/${notificationId}/read`,
    method: 'put'
  })
}

// 批量标记通知为已读
export const batchMarkAsRead = (userId, notificationIds) => {
  return request({
    url: `/api/notifications/user/${userId}/batch-read`,
    method: 'put',
    data: notificationIds
  })
}

// 标记所有通知为已读
export const markAllAsRead = (userId, type) => {
  return request({
    url: `/api/notifications/user/${userId}/mark-all-read`,
    method: 'put',
    params: { type }
  })
}

// 删除通知
export const deleteNotification = (userId, notificationId) => {
  return request({
    url: `/api/notifications/user/${userId}/${notificationId}`,
    method: 'delete'
  })
}

// 批量删除通知
export const batchDeleteNotifications = (userId, notificationIds) => {
  return request({
    url: `/api/notifications/user/${userId}/batch`,
    method: 'delete',
    data: notificationIds
  })
}

// 获取通知详情
export const getNotificationDetail = (userId, notificationId) => {
  return request({
    url: `/api/notifications/user/${userId}/${notificationId}`,
    method: 'get'
  })
}

// 获取通知统计
export const getNotificationStatistics = (userId) => {
  return request({
    url: '/api/notifications/statistics',
    method: 'get',
    params: { userId }
  })
}

// 获取用户通知偏好
export const getUserNotificationPreferences = (userId) => {
  return request({
    url: `/api/notifications/user/${userId}/preferences`,
    method: 'get'
  })
}

// 取消定时提醒
export const cancelScheduledReminder = (userId, reminderId) => {
  return request({
    url: `/api/notifications/user/${userId}/scheduled-reminder/${reminderId}/cancel`,
    method: 'put'
  })
}

// 更新通知设置
export const updateNotificationSettings = (userId, settings) => {
  return request({
    url: `/api/notifications/user/${userId}/settings`,
    method: 'put',
    data: settings
  })
}

// 获取通知设置
export const getNotificationSettings = (userId) => {
  return request({
    url: `/api/notifications/user/${userId}/settings`,
    method: 'get'
  })
}

// 处理待发送通知
export const processPendingNotifications = () => {
  return request({
    url: '/api/notifications/process-pending',
    method: 'post'
  })
}

// 重试失败通知
export const retryFailedNotifications = () => {
  return request({
    url: '/api/notifications/retry-failed',
    method: 'post'
  })
}

// 清理过期通知
export const cleanupExpiredNotifications = () => {
  return request({
    url: '/api/notifications/cleanup-expired',
    method: 'delete'
  })
}

// 发送测试通知
export const sendTestNotification = (userId, type = 'SYSTEM') => {
  return request({
    url: `/api/notifications/test`,
    method: 'post',
    data: {
      userId,
      type,
      title: '测试通知',
      content: '这是一条测试通知，用于验证通知系统是否正常工作。',
      priority: 'NORMAL'
    }
  })
}

// 获取通知模板
export const getNotificationTemplates = () => {
  return request({
    url: '/api/notifications/templates',
    method: 'get'
  })
}

// 创建通知模板
export const createNotificationTemplate = (data) => {
  return request({
    url: '/api/notifications/templates',
    method: 'post',
    data
  })
}

// 更新通知模板
export const updateNotificationTemplate = (templateId, data) => {
  return request({
    url: `/api/notifications/templates/${templateId}`,
    method: 'put',
    data
  })
}

// 删除通知模板
export const deleteNotificationTemplate = (templateId) => {
  return request({
    url: `/api/notifications/templates/${templateId}`,
    method: 'delete'
  })
}

// 预览通知
export const previewNotification = (data) => {
  return request({
    url: '/api/notifications/preview',
    method: 'post',
    data
  })
}

// 获取通知渠道状态
export const getNotificationChannelStatus = () => {
  return request({
    url: '/api/notifications/channels/status',
    method: 'get'
  })
}

// 测试通知渠道
export const testNotificationChannel = (channel, config) => {
  return request({
    url: `/api/notifications/channels/${channel}/test`,
    method: 'post',
    data: config
  })
}

// 获取通知发送历史
export const getNotificationSendHistory = (params) => {
  return request({
    url: '/api/notifications/send-history',
    method: 'get',
    params
  })
}

// 重新发送通知
export const resendNotification = (notificationId) => {
  return request({
    url: `/api/notifications/${notificationId}/resend`,
    method: 'post'
  })
}

// 获取通知发送统计
export const getNotificationSendStatistics = (params) => {
  return request({
    url: '/api/notifications/send-statistics',
    method: 'get',
    params
  })
}

// 导出通知数据
export const exportNotificationData = (params) => {
  return request({
    url: '/api/notifications/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 导入通知数据
export const importNotificationData = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/api/notifications/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取通知配置
export const getNotificationConfig = () => {
  return request({
    url: '/api/notifications/config',
    method: 'get'
  })
}

// 更新通知配置
export const updateNotificationConfig = (config) => {
  return request({
    url: '/api/notifications/config',
    method: 'put',
    data: config
  })
}

// 获取通知队列状态
export const getNotificationQueueStatus = () => {
  return request({
    url: '/api/notifications/queue/status',
    method: 'get'
  })
}

// 清空通知队列
export const clearNotificationQueue = () => {
  return request({
    url: '/api/notifications/queue/clear',
    method: 'delete'
  })
}

// 暂停通知发送
export const pauseNotificationSending = () => {
  return request({
    url: '/api/notifications/sending/pause',
    method: 'post'
  })
}

// 恢复通知发送
export const resumeNotificationSending = () => {
  return request({
    url: '/api/notifications/sending/resume',
    method: 'post'
  })
}

// 获取通知发送状态
export const getNotificationSendingStatus = () => {
  return request({
    url: '/api/notifications/sending/status',
    method: 'get'
  })
}